<{include file="public/header.html"}>
		<div class="xinsu-section">
			<div class="xinsu-equity">
				<ul class="xinsu-cross-title">
					<li <{if $common_info.action == 'index'}>class="xinsu-current"<{/if}>><a href="/stock">持仓单</a></li>
					<li <{if $common_info.action == 'trust'}>class="xinsu-current"<{/if}>><a href="/stock/trust">委托单</a></li>
					<li <{if $common_info.action == 'delivery'}>class="xinsu-current"<{/if}>><a href="/stock/delivery">交割单</a></li>
					<div class="xinsu-clear"></div>
				</ul>
				<div class="xinsu-equity-con" id="xinsu-trust-list">
					<{if $common_info.action == 'h_trust'}>
					<div class="xinsu-cross-search">
						<form class="xinsu-form" method="get">
							<input id="begin_time" class="xinsu-input" type="text" readonly name="begin_time" placeholder="开始日期" data-lcalendar="2011-01-1,<{date('Y-m-d')}>" value="<{if 0 != $begin_time}><{$begin_time}><{/if}>"/>
							<span>--</span>
							<input id="end_time"  class="xinsu-input01" type="text" readonly name="end_time" placeholder="结束日期" data-lcalendar="2011-01-1,<{date('Y-m-d')}>" value="<{if 0 != $begin_time}><{$end_time}><{/if}>"/>
							<button class="xinsu-btn">查询</button>
						</form>
					</div>
					<{/if}>
					<{if empty($list) == false}>
					<{foreach $list as $val}>
					<div class="xinsu-equity-list" data="<{$val.id}>">
						<div class="xinsu-equity-list-title">
							<span>编号：<{$val.id}></span>
							<p>委托时间：<{date("Y-m-d H:i:s",$val["stock_trust_time"])}></p>
						</div>
						<ul>
							<li>
								<p>股票名称：<{$val.stock_name}></p>
								<p>委托价：<{$val.price}></p>
								<p>委托数量：<{$val.num}></p>
							</li>
							<li>
								<p>类型：<{if $val.bull_type == 1}><span class="xinsu-color-red">融资↑</span><{else}><span class="xinsu-color-green">融券↓</span><{/if}></p>
								<p>最新价：<span class="xinsu-color-red" id="xinsu-price-<{$val.id}>">--</span></p>
								<p>买/卖：<{if $val.trust_type == 1}><span class="xinsu-color-red">买</span><{else}><span class="xinsu-color-green">卖</span><{/if}></p>
							</li>
							<div class="xinsu-clear"></div>
						</ul>
						<p>状态：
							<span class="xinsu-sell" id="xinsu-mange-<{$val.id}>">
								<{if $val.status == 0}>
								<a class="xinsu-color-blue xinsu-stock-cancel" href="javascript:;" data="<{$val.id}>" data-type="<{$val.trust_type}>">撤单</a>
								<{else}>
								--
								<{/if}>
							</span>
						</p>
					</div>
					<{/foreach}>
					<{/if}>
				</div>
			</div>
		</div>
		<link rel="stylesheet" href="<{STATIC_SERVER}>/mobile/css/lCalendar.css" />
		<script src="<{STATIC_SERVER}>/mobile/js/lCalendar.js"></script>
		<script>
			$(".xinsu-stock-cancel").click(function(){
				var url = "/stock/ajax_set_trust";
				var id = $(this).attr("data");
				var trust_type = $(this).attr("data-type");
				layer.confirm('您确定要撤销么？', {icon: 3}, function () {
					layer.closeAll();
					http_request_post(url, {id:id, trust_type:trust_type}, function(res) {
						layer.msg(res.msg, {icon: 1, time: 800}, function () {
							location.reload();
						});
					});
				});
			})
			<{if empty($list) == false}>
			$(function(){
				get_trust();
			})
			var stock = 0;
			//获取最新价格
			function get_trust() {
				if (stock >= 0) {
					var url = "/stock/ajax_get_trust";
					var data = "";
					$(".xinsu-equity-list").each(function(){
						var tmp = $(this).attr("data");
						if (tmp != undefined) {
							data += "," + tmp;
						}
					})
					http_request_post(url, {data:data}, function(result) {
						var res = result.data;
						$.each(res, function(key, val){
							var obj = $("#xinsu-stock-" + key).find(".weui-flex__item");
							if (val.status == 1) {
								//已完成
								$("#xinsu-price-"+key).html("--");
								$("#xinsu-mange-"+key).html("已完成");
								$("#xinsu-mange-"+key).addClass("xinsu-color-red");
							} else if (val.status == 2) {
								//已撤销
								$("#xinsu-price-"+key).html("--");
								$("#xinsu-mange-"+key).html("已撤销");
								$("#xinsu-mange-"+key).removeClass("xinsu-color-green");
							} else {
								//委托中
								$("#xinsu-price-"+key).html(val["price"]);
								$("#xinsu-mange-"+key).addClass("xinsu-color-green");
							}
						})
					});
				}
				stock = setTimeout("get_trust();", 1000);		
			}
			<{/if}>
			<{if $common_info.action == 'h_trust'}>
			//日期选择控件
			var calendar = new lCalendar();
			calendar.init({
				'trigger': '#begin_time',
				'type': 'date'
			});
			//日期选择控件
			var calendar = new lCalendar();
			calendar.init({
				'trigger': '#end_time',
				'type': 'date'
			});
			var url = "/stock/<{$common_info.action}>/<{$begin_time}>/<{$end_time}>/";
			<{else}>
			var url = "/stock/<{$common_info.action}>/";
			<{/if}>
			
			//自动加载
			var p = 2;
			var tmp = 0;
			
			$(window).scroll(function() {
				var scrollTop = $(this).scrollTop();
				var scrollHeight = $(document).height();
				var windowHeight = $(this).height();
				if (scrollTop + windowHeight == scrollHeight) {
					if (tmp != p) {
						//防止重复执行
						tmp = p;
						http_request_post(url + p, {}, function(result){
							if (result.status == 1 && result.data != "") {
								var html = "";
								$.each(result.data, function(key, val){
									//股票类型
									if (val.bull_type == 1) {
										var bull_type = '<span class="xinsu-color-red">融资↑</span>';
									} else {
										var bull_type = '<span class="xinsu-color-green">融券↓</span>';
									}
									
									//交易类型
									if (val.trust_type == 1) {
										var trust_type = '<span class="xinsu-color-red">买</span>';
									} else {
										var trust_type = '<span class="xinsu-color-green">卖</span>';
									}
									
									//交易状态
									if (val.status == 1) {
										var status = '<a class="xinsu-color-blue xinsu-stock-cancel" href="javascript:;" data="'+val.id+'" data-type="'+val.trust_type+'">撤单</a>';
									} else {
										var status = '--';
									}
									
									html += '<div class="xinsu-equity-list" data="'+val.id+'"><div class="xinsu-equity-list-title"><span>编号：'+val.id+'</span><p>委托时间：'+val.trust_time+'</p></div><ul><li><p>股票名称：'+val.stock_name+'</p><p>委托价：'+val.price+'</p><p>委托数量：'+val.num+'</p></li><li><p>类型：'+bull_type+'</p><p>最新价：<span class="xinsu-color-red" id="xinsu-price-'+val.id+'">--</span></p><p>买/卖：'+trust_type+'</p></li><div class="xinsu-clear"></div></ul><p>状态：<span class="xinsu-sell" id="xinsu-mange-'+val.id+'">'+status+'</span></p></div>';
								})
								$("#xinsu-trust-list").append(html);
								p ++;
							}
						});
					}
				}
			});
		</script>
<{include file="public/footer.html"}>